<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>微电影管理系统</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/resource/static/base/images/logo.png">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/resource/static/admin/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/static/fonts/css/font-awesome.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/static/ionicons/css/ionicons.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/static/admin/dist/css/AdminLTE.min.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/resource/static/admin/dist/css/skins/_all-skins.min.css">
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/resource/static/admin/plugins/datepicker/datepicker3.css">
    <style>
        * {
            font-family: "Microsoft YaHei";
        }

        .table > tbody > tr > td, .table > tbody > tr > th, .table > tfoot > tr > td, .table > tfoot > tr > th, .table > thead > tr > td, .table > thead > tr > th {
            vertical-align: middle;
            text-align: center;
        }

    </style>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <%@ include file="../5-public/AdminSidebar.jsp" %>

    <div class="content-wrapper">
        <!--内容-->
        <section class="content-header">
            <h1>微电影管理系统</h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 日志管理</a></li>
                <li class="active">管理员登录日志列表</li>
            </ol>
        </section>
        <section class="content" id="showcontent">
            <div class="row">
                <div class="col-md-12">
                    <div class="box box-primary">
                        <div class="box-header">
                            <h3 class="box-title">管理员登录日志列表</h3>
                            <div class="box-tools">
                                <div class="input-group input-group-sm" style="width: 150px;">
                                    <input type="text" name="table_search" class="form-control pull-right"
                                           id="AdminCondition" placeholder="请输入关键字...">

                                    <div class="input-group-btn" onclick="getCondition()">
                                        <button type="submit" class="btn btn-default"><i class="fa fa-search"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="box-body table-responsive no-padding">
                            <table class="table table-hover">
                                <thead>
                                <tr>
                                    <th>管理员</th>
                                    <th>登录时间</th>
                                    <th>登录IP</th>
                                    <th>登录地址</th>
                                </tr>
                                </thead>
                                <tbody id="adminloglist">
                                <c:forEach items="${adminloglist.list}" var="adminlist">
                                    <c:forEach items="${adminlist.logs}" var="log">
                                        <tr>
                                            <th>${adminlist.personName}</th>
                                            <th>${log.loginTime}</th>
                                            <th>${log.ip}</th>
                                            <c:choose>
                                                <c:when test="${log.loginAddress!=null}"><th style="width:30%">${log.loginAddress}</th></c:when>
                                                <c:otherwise><th style="width:30%">暂无数据</th></c:otherwise>
                                            </c:choose>
                                        </tr>
                                    </c:forEach>
                                </c:forEach>
                                </tbody>
                            </table>
                        </div>
                        <div id="adminlogpage" class="box-footer clearfix">
                            <ul class="pagination pagination-sm no-margin pull-right">
                                <li><a href="#" onclick="getAdminLog(1)">首页</a></li>
                                <c:choose>
                                <c:when test="${adminloglist.isFirstPage}">
                                <li><a href="#" onclick="getAdminLog(1)">上一页</a></li>
                                </c:when>
                                <c:otherwise>
                                <li><a href="#" onclick="getAdminLog(${adminloglist.pageNum-1})">上一页</a></li>
                                </c:otherwise>
                                </c:choose>
                                <li><a href="#">${adminloglist.pageNum}</a></li>
                                <c:choose>
                                <c:when test="${adminloglist.pageNum>=adminloglist.pages}">
                                <li><a href="#" onclick="getAdminLog(${adminloglist.pages})">下一页</a></li>
                                </c:when>
                                <c:otherwise>
                                <li><a href="#" onclick="getAdminLog(${adminloglist.pageNum + 1})">下一页</a></li>
                                </c:otherwise>
                                </c:choose>
                                <li><a href="#" onclick="getAdminLog(${adminloglist.pages})">尾页</a></li>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <!--内容-->
    </div>
    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>版本</b> 1.0
        </div>
        <strong>版权 &copy; 2017-2018 归<a href="">xxx</a>.</strong> 所有
    </footer>
    <div class="control-sidebar-bg"></div>
</div>
<script src="${pageContext.request.contextPath}/resource/static/admin/plugins/jQuery/jQuery-2.2.0.min.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/plugins/fastclick/fastclick.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/dist/js/app.min.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/dist/js/demo.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"
        charset="UTF-8"></script>
<script>
    function getAdminLog(index) {
        var condition = $("#AdminCondition").val();
        var data = {
            "pageNum": index,
            "pageSize": 10,
            "role": 1,
            "Condition": condition
        }
        $.ajax({
            url: "/person/logsPageInfo",
            data: data,
            type: "get",
            dataType: "json",
            success: function (res) {
                var body = $("#adminloglist");
                body.empty();
                for (let i = 0; i < res.data.list.length; i++) {
                    for (let j = 0; j < res.data.list[i].logs.length; j++) {
                        var time = new Date(res.data.list[i].logs[j].loginTime).toLocaleTimeString();
                        var date = new Date(res.data.list[i].logs[j].loginTime).toLocaleDateString();
                        var tr = '<tr>' +
                            '<th>' + res.data.list[i].personName + '</th>' +
                            '<th>' + date + '&nbsp;' + time + '</th>' +
                            '<th>' + res.data.list[i].logs[j].ip + '</th>';
                        if (res.data.list[i].logs[j].loginAddress != null) {
                            tr = tr + '<th style="width:30%">' + res.data.list[i].logs[j].loginAddress + '</th>';
                        } else {
                            tr = tr + '<th style="width:30%">暂无数据</th>';
                        }
                        tr = tr + '</tr>';
                        body.append(tr);
                    }
                }
                var page = $("#adminlogpage");
                page.empty();
                var li = '<ul class="pagination pagination-sm no-margin pull-right">' +
                    '<li><a href="#" onclick="getAdminLog(1)">首页</a></li>';
                if (res.data.pageNum > 1) {
                    li = li + '<li><a href="#" onclick="getAdminLog(' + (res.data.pageNum - 1) + ')">上一页</a></li>';
                } else {
                    li = li + '<li><a href="#" onclick="getAdminLog(' + res.data.pageNum + ')">上一页</a></li>';
                }
                li = li + '<li><a href="#">' + res.data.pageNum + '</a></li>'
                if (res.data.pageNum >= res.data.pages) {
                    li = li + '<li><a href="#" onclick="getAdminLog(' + (res.data.pages) + ')">下一页</a></li>'
                } else {
                    li = li + '<li><a href="#" onclick="getAdminLog(' + (res.data.pageNum + 1) + ')">下一页</a></li>'
                }

                li = li + '<li><a href="#" onclick="getAdminLog(' + res.data.pages + ')">尾页</a></li>' + '</ul>';
                page.append(li);
            },
            error: function () {
                alert("小二正忙，一会再试");
            }
        })
    }

    function getCondition() {
        var condition = $("#AdminCondition").val();
        var data = {
            "pageNum": 1,
            "pageSize": 10,
            "role": 0,
            "Condition": condition
        }
        $.ajax({
            url: "/person/logsSelect",
            data: data,
            type: "get",
            dataType: "json",
            success: function (res) {
                if (res.code == "200") {
                    var body = $("#userloglist");
                    body.empty();
                    for (let i = 0; i < res.data.list.length; i++) {
                        for (let j = 0; j < res.data.list[i].logs.length; j++) {
                            var time = new Date(res.data.list[i].logs[j].loginTime).toLocaleTimeString();
                            var date = new Date(res.data.list[i].logs[j].loginTime).toLocaleDateString();
                            var tr = '<tr>' +
                                '<th>' + res.data.list[i].personName + '</th>' +
                                '<th>' + date + '&nbsp;' + time + '</th>' +
                                '<th>' + res.data.list[i].logs[j].ip + '</th>';
                            if (res.data.list[i].logs[j].loginAddress != null) {
                                tr = tr + '<th style="width:30%">' + res.data.list[i].logs[j].loginAddress + '</th>';
                            } else {
                                tr = tr + '<th style="width:30%">暂无数据</th>';
                            }
                            tr = tr + '</tr>';
                            body.append(tr);
                        }
                    }
                    var page = $("#adminlogpage");
                    page.empty();
                    var li = '<ul class="pagination pagination-sm no-margin pull-right">' +
                        '<li><a href="#" onclick="getAdminLog(1)">首页</a></li>';
                    if (res.data.pageNum > 1) {
                        li = li + '<li><a href="#" onclick="getAdminLog(' + (res.data.pageNum - 1) + ')">上一页</a></li>';
                    } else {
                        li = li + '<li><a href="#" onclick="getAdminLog(' + res.data.pageNum + ')">上一页</a></li>';
                    }
                    li = li + '<li><a href="#">' + res.data.pageNum + '</a></li>'
                    if (res.data.pageNum >= res.data.pages) {
                        li = li + '<li><a href="#" onclick="getAdminLog(' + (res.data.pages) + ')">下一页</a></li>'
                    } else {
                        li = li + '<li><a href="#" onclick="getAdminLog(' + (res.data.pageNum + 1) + ')">下一页</a></li>'
                    }

                    li = li + '<li><a href="#" onclick="getAdminLog(' + res.data.pages + ')">尾页</a></li>' + '</ul>';
                    page.append(li);
                } else {
                    alert(res.msg);
                }

            },
            error: function () {
                alert("小二正忙，一会再试");
            }
        })
    }




</script>

</body>
</html>